//
//  EFComposeEmotionView.m
//  WZEfengAndEtong
//
//  Created by wanzhao on 16/3/7.
//  Copyright © 2016年 wanzhao. All rights reserved.
//

#import "EFComposeEmotionView.h"
#import "UIUtil.h"
#import "MicroDef.h"
#import "EFComposEmotionPageView.h"
#import "MJExtension.h"
#import "EMotionModel.h"
#import "CHEmotionHelper.h"


static EFComposeEmotionView *shared;

@implementation EFComposeEmotionView

@synthesize horizMenu = _horizMenu;
@synthesize emoScroll = _emoScroll;
@synthesize items = _items;
@synthesize pageCon = _pageCon;

- (void)dealloc
{
    
}

+(EFComposeEmotionView*)defaultComposeEmotionView
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        if(shared == nil)
        {
            shared = [[EFComposeEmotionView alloc] init];
        }
    });
    
    return shared;
}

+ (EFComposeEmotionView *)defaultComposeEmoViewWithDelegate:(id)sender
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        if(shared == nil)
        {
            shared = [[EFComposeEmotionView alloc] init];
            shared.emoScroll.delegate = sender;
        }
    });
    
    return shared;
}

- (id)init
{
    self = [super init];
    if (self) {
        self.backgroundColor = RGBCOLOR(237, 237, 237);
        self.frame = CGRectMake(0, HARDWARE_SCREEN_HEIGHT - StatusBarHeight - 44.0f, HARDWARE_SCREEN_WIDTH, 180);
        self.emoPageView = [EFComposEmotionPageView defaultComposeEmoPageView];
        _horizMenu = [[EFengComposeEmotionToolView alloc] init];
        
        
        [self setDesign:nil];
    }
    return self;
}

-(void)setDesign:(id)sender
{
    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 0, HARDWARE_SCREEN_WIDTH, 0.5f)];
    line.backgroundColor = RGBCOLOR(212, 212, 212);
    [self addSubview:line];
    
    self.emoPageView.backgroundColor = RGBCOLOR(237, 237, 237);
    [self addSubview:self.emoPageView];
    self.emoPageView.frame = CGRectMake(0, 0.5, HARDWARE_SCREEN_WIDTH, 140.0f);
    self.emoPageView.emotionArray = [CHEmotionHelper defaultEmotions];
    
    [_horizMenu setFrame:CGRectMake(0,140, HARDWARE_SCREEN_WIDTH, 40)];
    _horizMenu.backgroundColor = RGBCOLOR(237, 237, 237);
    _horizMenu.eFengComposeEmotionToolViewDelegate = self;
    [self addSubview:self.horizMenu];
    
    
}

- (void)EFengComposeEmotionToolViewDidSure
{
    if ([self.eFComposeEmotionViewDelegatedelegate respondsToSelector:@selector(eFComposeEmotionViewViewDidSure)]) {
        [self.eFComposeEmotionViewDelegatedelegate eFComposeEmotionViewViewDidSure];
    }
}

- (void)emotiontoolViewDidSelectEmotionWithType:(NSString *)emotionType
{
    if ([emotionType isEqualToString:@"defaultEmotion"]) {
        self.emoPageView.emotionArray = [CHEmotionHelper defaultEmotions];
    } else if ([emotionType isEqualToString:@"rencentEmotion"]){
        self.emoPageView.emotionArray = [CHEmotionHelper recentEmotions];
    }
}

#pragma mark -
#pragma mark HorizMenu Delegate
-(void) horizMenu:(MKHorizMenu *)horizMenu itemSelectedAtIndex:(NSUInteger)index
{
    //    if (index==0) {
    //        //显示发送
    //        [UIView beginAnimations:nil context:NULL];
    //        [UIView setAnimationDuration:0.3];
    //        [_sendBtn setFrame:CGRectMake(self.horizMenu.frame.size.width - 60,self.horizMenu.frame.origin.y+5, 50, 30)];
    //        [UIView commitAnimations];
    //    }else
    //    {
    //        [UIView beginAnimations:nil context:NULL];
    //        [UIView setAnimationDuration:0.3];
    //        [_sendBtn setFrame:CGRectMake(self.horizMenu.frame.size.width + 1 ,self.horizMenu.frame.origin.y+5, 50, 30)];
    //        [UIView commitAnimations];
    //    }
    //    self.selectionItemLabel.text = [self.items objectAtIndex:index];
}



@end
